#!/usr/bin/python3

import os
import shutil
import wstage4
import wstage4.os_win7
import subprocess


os.makedirs("./t", exist_ok=True)
wdir = wstage4.WorkDir("./t", reset=True)

s = wstage4.Settings()
s.program_name = "test"
s.verbose_level = 1

ts = wstage4.os_win7.TargetSettings()
if True:
    ts.arch = wstage4.Arch.X86_64
    ts.version = wstage4.Version.WINDOWS_7
    ts.edition = wstage4.Edition.WINDOWS_7_ULTIMATE
    ts.lang = wstage4.Lang.en_US
    ts.product_key = "PPBK3-M92CH-MRR9X-34Y9P-7CH2F"
    installIsoFile = wstage4.os_win7.CloudInstallationMedia(ts.arch, ts.version, ts.edition, ts.lang, local_iso_filepath="./inst.iso", local_virtio_win_iso_filepath="./virtio.iso")
    if not os.path.exists("./inst.iso"):
        installIsoFile.download()
    else:
        installIsoFile._bDownloaded = True

ts.user_name = "fpemud"
ts.timezone = "Eastern Standard Time"
ts.keyboard_layout = "US"
ts.locale = "1033:00000409"
ts.extra_drivers = []

with wstage4.Builder(s, ts, wdir) as builder:
    print("        - Prepare...")
    builder.action_prepare(installIsoFile)

    print("        - Installing windows...")
    builder.action_install_os()

    print("        - Installing core applications...")
    builder.action_install_applications()

    builder.add_and_run_custom_action("set_background", wstage4.os_win7.custom_actions.SetBackground(wstage4.os_win7.custom_actions.SetBackground.BackgroundType.SOLID_COLOR, 0x000000))
    builder.add_and_run_custom_action("show_hide_desktop_icons", wstage4.os_win7.custom_actions.ShowHideDesktopIcons({"recycle-bin": False}))

    print("        - Cleaning up...")
    builder.action_cleanup()

    #print("        - Finish...")
    #builder.finish()

if os.path.exists("./t.bak"):
    shutil.rmtree("./t.bak")
subprocess.check_call(["cp", "-r", "./t", "./t.bak"])
